package com.bookstore.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bookstore.entity.Book;
import com.bookstore.mapper.BookMapper;
import com.bookstore.service.BookService;
import org.springframework.stereotype.Service;

@Service
public class BookServiceImpl extends ServiceImpl<BookMapper, Book> implements BookService {

    @Override
    public IPage<Book> getBooksByPage(int page, int size) {
        return page(new Page<>(page, size));
    }

    @Override
    public IPage<Book> getBooksByCategory(Integer categoryId, int page, int size) {
        LambdaQueryWrapper<Book> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Book::getCategoryId, categoryId);
        return page(new Page<>(page, size), queryWrapper);
    }

    @Override
    public IPage<Book> searchBooks(String keyword, int page, int size) {
        LambdaQueryWrapper<Book> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(Book::getTitle, keyword)
                .or()
                .like(Book::getDescription, keyword);
        return page(new Page<>(page, size), queryWrapper);
    }
} 